package com.suoluo.zenadmin.controllers.admin.assets;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.web.multipart.MultipartFile;

import net.paoding.rose.web.Invocation;
import net.paoding.rose.web.annotation.Path;
import net.paoding.rose.web.annotation.rest.Get;
import net.paoding.rose.web.annotation.rest.Post;

import com.suoluo.zenadmin.common.CommonResp;
import com.suoluo.zenadmin.controllers.JSONInterceptor.JSON;
import com.suoluo.zenadmin.service.country.CountryService;
import com.suoluo.zenadmin.vo.country.ContinentVO;
import com.suoluo.zenadmin.vo.country.CountryVO;

@Path("/")
public class AssetsController {

	@Resource(name="countryService")
	private CountryService countryService;
	
	@Get("index")
	public String toIndex(){
		return "index";
	}
	
	@SuppressWarnings("rawtypes")
	@Get("vlist")
	public String toListCountry(Invocation inv){
		List<Map> list = countryService.findListCountry(0, 30);
		inv.addModel("country",list);
		
		return "listTables";
	}
	@Get("vsave")
	public String toAddCountry(Invocation invo) {
		
		List<ContinentVO> list = countryService.findListContinent();
		invo.addModel("continent",list);
		return "addCountry";
	}

	@JSON
	@Post("save")
	public Object saveCountry(Invocation inv,CountryVO countryVO) {
			
			countryService.saveCountry(countryVO);
			return CommonResp.SUCCESS;
	}
	@Get("vupdate")
	public String toUpdate(Invocation invo) {
		int countryId = Integer.parseInt(invo.getParameter("countryId"));
		CountryVO country = countryService.findCountryById(countryId);
		invo.addModel("country", country);
		List<ContinentVO> list = countryService.findListContinent();
		invo.addModel("continent",list);
		return "updateCountry";
	}

	
	@Post("update")
	public String update(Invocation inv,CountryVO countryVO) {
			countryService.update(countryVO);
			return toListCountry(inv);
	}
	@JSON
	@Post("delete")
	public Object delete(CountryVO country) {
		countryService.delete(country);
		return CommonResp.SUCCESS;
	}

}
